﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi
{
    [CPPEI.WebApi.AuthPostAction("ETL", "UpdateDataSource", "1.0")]
    public class UpdateDataSourceAction : BaseAction<UpdateDataSourceParams, UpdateDataSourceResult>
    {
        protected override ActionResult<UpdateDataSourceResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            UpdateDataSourceParams opParams)
        {
            SER.DtSerService service = new SER.DtSerService();
            ServiceResult result = service.UpdateDtSource(context.UserId, opParams.DataSourceId, opParams.Name, opParams.Value);
            if(result.IsSuccess)
            {
                return new ActionResult<UpdateDataSourceResult>(new UpdateDataSourceResult());
            }
            else
            {
                return new ActionResult<UpdateDataSourceResult>(result.IsSuccess, result.ErrorCode, result.Message, null);
            }
        }
    }

    public class UpdateDataSourceParams
    {
        [Parameter]
        public Guid DataSourceId { get; set; }

        [Parameter]
        public string Name { get; set; }

        [Parameter]
        public string Value { get; set; }
    }

    public class UpdateDataSourceResult
    {
    }
}
